package com.letv.thrift;

import java.util.ArrayList;
import java.util.List;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import serving.GenericDetailRequest;
import serving.GenericDetailResponse;
import serving.GenericDetailServing;

/**
 * test for all thrift interface
 */
public class ThriftTest {

    public static void main(String[] args) {
        try {
            // test China new
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.118.31.44", 9090, 200000));
            // test China test orginal
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.118.31.44", 9092, 200000));
            // production China
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.11.145.3", 9090, 200000));
            // production us
//            TTransport tTransport = new TFastFramedTransport(new TSocket("107.155.52.73", 9090, 200000));
            // production india1
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.121.152.22", 9090, 200000));
            // production india2
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.121.152.25", 9090, 200000));
            // production india3
//            TTransport tTransport = new TFastFramedTransport(new TSocket("10.121.152.26", 9090, 200000));
            // production india4
            TTransport tTransport = new TFastFramedTransport(new TSocket("10.121.152.28", 9090, 200000));
            TProtocol tProtocol = new TBinaryProtocol(tTransport, true, true);
            tTransport.open();
            ThriftTest.testDetail(tProtocol);
            tTransport.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * test detail interface
     * @param tProtocol TProtocol
     */
    public static void testDetail(TProtocol tProtocol) {
        try {
            GenericDetailRequest genericDetailRequest = new GenericDetailRequest();
            List<String>  ids = new ArrayList<String>();
            // leso album
            ids.add("205_390639");
            // cp
//            ids.add("211_-4761831624443009718");
            genericDetailRequest.setIds(ids);
            genericDetailRequest.setVideo_list_start_idx((short)0);
            genericDetailRequest.setVideo_list_num((short)10);
//            genericDetailRequest.setCp_request_type((short)1);
            long beginTime = System.currentTimeMillis();
            GenericDetailServing.Client client = new GenericDetailServing.Client(tProtocol);
            GenericDetailResponse genericDetailResponse = client.GetDetailInfo(genericDetailRequest);
            System.out.println(System.currentTimeMillis() - beginTime);
            System.out.println(genericDetailResponse);
            System.out.println(genericDetailResponse.getDetails());
        } catch(Exception e) {
            
        }
    }
}
